local base = game_mode.netbase
local city = class("city_mode",base)

city.roomMax = 20
city.roomMin = 2
city.roomLast = 60*10
city.mapName = "capture"
city.teamCount = 2
city.itemGenCD = 30
city.itemGenTypes = {1,2,3,4,5,6,7}
city.npcGenCD = -1
city.enablePlayerRebirth = true
city.playerRebirthCD = 1
city.playerBirthCollCheck = true
city.playerGenTypes = {1,2,3,4,5,6,7,8}

function city:onInit()
    self.hq = {self:newHQ(1),self:newHQ(2)}
end

function city:newHQ(team)
    local hq
    if team == 1 then
        hq = HQ(self,30,1,1)
    elseif team == 2 then
        hq = HQ(self,30,self.map.h-1,2)
    end
    self:setNetObj(hq)
    return hq
end



function city:getPlayerBirthPos(player)
    self.playerGenPos = self.playerGenPos or {}
    if self.playerGenPos[player.team] then return self.playerGenPos[player.team] end
    local pos = {
        minX = 1,
        maxX = self.map.w-1,
        minY = 1,
        maxY = self.map.h-1
        }
    if player.team == 1 then
        pos.maxY = 1
    elseif player.team == 2 then
        pos.minY = self.map.h-1
    end
    self.playerGenPos[player.team] = pos
    return pos
end

function city:onUpdate(dt)
    if self.state == "done" then return end
    if self.hq[1].fallen then
        self.state = "done"
        delay:new(2,
            function() self:gameOver({team_2 = "win",team_1 = "lose"}) end
            )
    elseif self.hq[2].fallen then
        self.state = "done"
        delay:new(2,
            function() self:gameOver({team_1 = "win",team_2 = "lose"}) end
            )
    end
end

return city